using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using PccCommonForC;

public partial class Pub_Module_J_Menu : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindData();
        }
    }

    private void BindData()
    {

        clsWebShop cls = new clsWebShop();
        DataSet ds = new DataSet();

        DataTable dtTopic = new DataTable();
        DataTable dtCat = new DataTable();
        PccMsg msg = new PccMsg();
        msg.CreateFirstNode("KindNo", "");
        ds = cls.Get_Topic_Catalogue(msg.GetXmlStr);
        dtTopic = ds.Tables[0];
        dtCat = ds.Tables[1];
        string HTMLFilm = "<div class='T_Right' width='190px' style='padding-top:10px'>";
        HTMLFilm += "<div class='glossymenu'>";

        string HTML = "<div class='T_Right' width='190px'>";
        HTML += "<div class='glossymenu'>";

        string TopicID, TopicName, CatID, CatName;
        string Url = ResolveUrl("~/");
        bool isFilm = false;
        foreach (DataRow rowTopic in dtTopic.Rows)//Cap Cha
        {

            TopicID = rowTopic["TopicID"].ToString();
            TopicName = rowTopic["TopicName"].ToString();

            DataRow[] rowCat;
            rowCat = dtCat.Select("TopicID=" + TopicID);

            if (rowCat.Length > 0)
            {
                for (int i = 0; i < rowCat.Length; i++)
                {
                    if (TopicID.Equals(rowCat[i]["TopicID"].ToString()) && "F".Equals(rowCat[i]["KindNo"].ToString()))
                    {
                        isFilm = true;
                        break;
                    }
                }
                if (isFilm)
                {
                    HTMLFilm += "<a class='menuitem submenuheaderFilm'   href='" + Url + "Stall/" + TopicID + "/0/0/0.aspx'><img src='" + Url + "Images/Body/menu/icon_arrow3.gif'>&nbsp;&nbsp;" + TopicName + "</a>";
                    HTMLFilm += "<div class='submenuFilm'>";
                    HTMLFilm += "<ul>";
                }
                else
                {
                    HTML += "<a class='menuitem submenuheader'   href='" + Url + "Stall/" + TopicID + "/0/0/0.aspx'><img src='" + Url + "Images/Body/menu/icon_arrow3.gif'>&nbsp;&nbsp;" + TopicName + "</a>";
                    HTML += "<div class='submenu'>";
                    HTML += "<ul>";
                }
                for (int i = 0; i < rowCat.Length; i++)
                {
                    string tmp = "<li><a href='{0}{1}/0/{2}/0/0.aspx' class='{3}' >{4}</a></li>";
                    CatID = rowCat[i]["CatID"].ToString();
                    CatName = rowCat[i]["CatName"].ToString();
                    if (rowCat[i]["KindNo"].ToString() == "P")
                    {
                        string css = "";
                        if (CatID.Equals(getCatID)) css = "selected"; else css = "";
                        HTML += string.Format(tmp, Url, "Stall", CatID, css, CatName);

                    }
                    if (isFilm)
                    {
                        string css = "";
                        if (CatID.Equals(getCatID)) css = "selected"; else css = "";
                        HTMLFilm += string.Format(tmp, Url, "Film", CatID, css, CatName);
                    }
                }
                if (isFilm)
                {
                    HTMLFilm += "</ul>";
                    HTMLFilm += "</div>";
                }
                else
                {
                    HTML += "</ul>";
                    HTML += "</div>";
                }

            }
            /*   else
               {
                   HTML += "<a class='menuitem' href='" + Url + "Stall/" + TopicID + "/0/0/0'>" + TopicName + "</a>";
               }*/
        }
        HTML += "</div>";
        HTML += "</div>";
        HTMLFilm += "</div>";
        HTMLFilm += "</div>";
        ltrMenu.Text = HTML;
        ltrMenuFilm.Text = HTMLFilm;


    }
    public string getCatID
    {
        get
        {
            return Request.QueryString["CatID"];
        }
    }
}
